<?php
namespace App\Modules\Relationship\Models;


use App\Http\Services\CommonServices;
use App\Modules\Relationship\Interfaces\ModelInterface;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use App\Http\Model\Base;

class KeepsakeUpgradeLogModel extends Base {

    // 戒指类型（0-经典戒指,1-荣誉戒指,2-等级戒指,3-其他戒指）
    protected $table = "rs_keepsake_upgrade_log";
    protected $fields = ['id', 'rs_code as rsCode', 'user_id as userId',
        'b_keepsake_id as bKeepsakeId', 'keepsake_id as keepsakeId', 'type', 'created_time as createdTime', 'upated_time as upatedTime', 'is_deleted as isDeleted'
    ];

    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);
        $this->tablePrefix = env('DB_PREFIX');
    }


    // 写入用户戒指记录表
    public function insert($rsCode, $userId, $bKeepsakeId, $keepsakeId, $type = 0) {
            DB::table($this->table)->insert([
                'rs_code' => $rsCode,
                'user_id' => $userId,
                'b_keepsake_id' => $bKeepsakeId,
                'keepsake_id' =>$keepsakeId,
                'type'=>$type
            ]);
    }

    // 获取信物升级记录
    public function selectLog ($rsCode, $userId, $type = 0) {
        $condition = array('rs_code'=>$rsCode, 'user_id'=>$userId, 'type'=>$type, 'is_deleted'=>0);
        return $this->getListByCondition($condition, $this->fields);
    }

}